package model;

import java.util.List;
import java.util.Map;
import util.DBUtil;

public class UserService {

	private DBUtil db;

	public UserService() {
		db = new DBUtil();
	}

	public Map<String, String> login(String username, String password) {
		String sql = "select * from user where username=? and password=?";
		return db.getMap(sql, new String[] { username, password });
	}
	
	//读取用户信息?
	public List<Map<String, String>> getUsers(String username) {
		  String sql = "select * from user";
		  String[] params = null;
		  if (username != null) {
		   sql = sql + " where username like ?";
		   params = new String[] { "%" + username + "%" };
		  }
		  return db.getList(sql, params);
		 }
	
	//读取用户信息?
		public List<Map<String, String>> getUsers2(String username, String telephone, String address) {
			  String sql = "select * from user";
			  String[] params = null;
			  if (username != null) {
			   sql = sql + " where username like ?";
			   params = new String[] { "%" + username + "%" };
			  }
			  return db.getList(sql, params);
			 }
		
		//删除
		public int DelUser(String id) {
			String[]
			params= {id};
			String sql="delect from diningcar where userid=?";
			db.update(sql,params);
			sql="delete from user where id=?";
			return db.update(sql,params);}
		
		//加入新用户
		   public int adduser (String un, String pw, String tel, String addr){
		        String[] params = {un,pw,tel,addr};      
		     String sql = "insert into user values(null,?,?,0,?,?)";
		     return db.update(sql, params);
		   
		   }
		   
		 //修改用户
		   public int changeuser (String userid,String un, String pw, String tel, String addr){
		        String[] params = {un,pw,tel,addr,userid};      
		     String sql = "update user set username=?, password=?, telephone=?, address=? where id=?";
		     return db.update(sql, params);
		   
		   }


}
